package net.kem.android.positioner;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class LocationPoller extends BroadcastReceiver {
	private static final String TAG = "LocationPoller";

	/**
	 * Standard entry point for a BroadcastReceiver. Delegates the event to
	 * LocationPollerService for processing.
	 */
	@Override
	public void onReceive(Context context, Intent intent) {
		// just make sure we are getting the right intent (better safe than sorry)
		if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
			Log.d(TAG, "Boot intent " + intent.toString() + "\t" + context.toString());
		}
//		else {
//			Log.e(TAG, "Received unexpected intent " + intent.toString());
//		}

//		ComponentName comp = new ComponentName(context.getPackageName(), PositionerService.class.getName());
//		ComponentName service = context.startService(new Intent().setComponent(comp).putExtra(PositionerService.EXTRA_SCHEDULLED_CALL, true));
		Intent serviceIntent = new Intent();
		serviceIntent.setAction("net.kem.android.positioner.PositionerService");
		serviceIntent.putExtra(PositionerService.EXTRA_SCHEDULLED_CALL, true);
		ComponentName service = context.startService(serviceIntent);

		Log.d(TAG, "Recurring alarm; " + intent.toString() + "\t" + context.toString());
		if(null == service) {
			// something really wrong here
			//Log.e(TAG, "Could not start service " + comp.toString());
		}
	}
}